/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Section;
import DataConnect.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
/**
 *
 * @author MyLaptop
 */
public class Section {
    
    public  int sectionID;
     public String sectionName;
    public int departmentID;
   
    
    public Section()
    {
        
    }

    public int getDepartmentID() {
        return departmentID;
    }

    public int getSectionID() {
        return sectionID;
    }

    public String getSectionName() {
        return sectionName;
    }

    public void setDepartmentID(int departmentID) {
        this.departmentID = departmentID;
    }

    public void setSectionID(int sectionID) {
        this.sectionID = sectionID;
    }

    public void setSectionName(String sectionName) {
        this.sectionName = sectionName;
    }
    
       public static Vector getAllSection() throws SQLException{
        Vector v = new Vector();
        try {
            ResultSet rs = DBHelper.executeQuery("spGetAllSection");
            while(rs.next()){
                Section obj = new Section();
               
                obj.sectionID = rs.getInt(1);
                obj.sectionName = rs.getString(2);
                 obj.departmentID = rs.getInt(3);
                
                v.add(obj);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;
    }
    public static Vector searchSectionByName(Vector name) throws SQLException{
        Vector v = new Vector();
        try {
            ResultSet rs = DBHelper.executeQuery("spSearchSectionByName",name);
            while(rs.next()){
                Section obj = new Section();
                obj.departmentID = rs.getInt(3);
                obj.sectionName = rs.getString(2);
                obj.sectionID = rs.getInt(1);
                v.add(obj);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;
    }
       
    public static int insertSection(Section obj) throws SQLException {
        int i = 0;
        try {
            Vector paramList = new Vector();
            paramList.add(obj.sectionName);
            paramList.add(obj.departmentID);
                       
            i = DBHelper.executeUpdate("spInsertSection",paramList);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return i;
    }
    
    public static int updateSection(Section obj) throws SQLException {
        int i=0;
        try {            
            Vector paramList = new Vector();
            paramList.add(obj.sectionID);
            paramList.add(obj.sectionName);
            paramList.add(obj.departmentID);
           
            i = DBHelper.executeUpdate("spUpdateSection",paramList);
        } catch(SQLException sqlex) {
            
        }
        return i;
    }
    
    public static int deleteSection(String sectionName) throws SQLException {
        int i=0;
        try {
            Vector paramList=new Vector();
            paramList.add(sectionName);
            i=DBHelper.executeUpdate("spDeleteSection",paramList);
        } catch(SQLException sqlex) {            
        }
        return i;
    }
    
}
